public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 =new Thread(()->{
            for (int i = 0; i < 3; i++) {
                System.out.println("t1");
                try {
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        });

        Thread t2 = new Thread(()->{
            for (int i = 0; i < 4; i++) {
                System.out.println("t2");
                try{
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        //主线程中调用多个join
        //先执行t1 如果t1还没结束 t1.join就阻塞等待
        //t1结束之后,main继续执行t2.join 等待t2结束
        System.out.println("main end");
    }
}
